package com.yunji.web.order;

import com.yunji.common.base.BaseController;
import com.yunji.common.base.response.Response;
import com.yunji.common.base.response.ResponseHelper;
import com.yunji.common.utils.ExcelUtil;
import com.yunji.order.business.RefundBusiness;
import com.yunji.order.dto.PlateRefundCreateDTO;
import com.yunji.order.dto.RefundParam;
import com.yunji.order.vo.RefundVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @Package com.yunji.web.order
 * FileName:	RefundController.java
 * Copyright:	Copyright © 2024 云集互联 All Rights Reserved
 * Company:		云集互联
 * @version: 1.0
 * @since: JDK 1.8.0_202
 * Create at:   2024-04-22 00:41:10
 * Description:
 * 商品退货
 * Modification History:
 * Author					Date					Version         Description
 * -------------------------------------------------------------------------------------
 * HuaAo0803@163.com	2024-04-22 00:41:10     1.0             1.0 Version
 */
@Api(tags = "管理端-退款模块")
@RestController
@RequestMapping("/container/refund/")
public class RefundController extends BaseController {
    @Resource
    private RefundBusiness refundBusiness;

    @ApiOperation("退款列表")
    @PostMapping("/list")
    public Response<List<RefundVO>> refundPage(@Valid @RequestBody RefundParam param) {
        List<RefundVO> list = refundBusiness.refundList(param);
        return ResponseHelper.successWithPage(list);
    }

    @ApiOperation("导出退款列表")
    @PostMapping("/export")
    public void export(@RequestBody RefundParam param) {
        param.setExport(true);
        List<RefundVO> list = refundBusiness.refundList(param);
        ExcelUtil<RefundVO> util = new ExcelUtil<>(RefundVO.class);
        util.exportExcel(response, list, "退款数据");
    }

    @ApiOperation("退款详情")
    @PostMapping("/getRefund/{refundId}")
    public Response<RefundVO> getRefund(@PathVariable("refundId") Long refundId) {
        return ResponseHelper.success(refundBusiness.getByRefundId(refundId));
    }

    @ApiOperation("同意退款")
    @PostMapping("/agreeRefund")
    public Response<String> agreeRefund(@RequestParam("refundId") Long refundId, @RequestParam("auditBackStock") Integer auditBackStock) {
        refundBusiness.passRefund(refundId, auditBackStock);
        return ResponseHelper.success();
    }

    @ApiOperation("拒绝退款")
    @PostMapping("/rejectRefund")
    public Response<String> rejectRefund(@RequestParam("refundId") Long refundId, @RequestParam("rejectReason") String rejectReason) {
        refundBusiness.rejectRefund(refundId, rejectReason);
        return ResponseHelper.success();
    }

    @ApiOperation("平台主动退款")
    @PostMapping("/plateRefund")
    public Response<?> plateRefund(@Valid @RequestBody PlateRefundCreateDTO dto) {
        return ResponseHelper.success(refundBusiness.createPlateRefund(dto));
    }
}